
  ___  ____  ____  ____  ____ ®
 /__    /   ____/   /   ____/      18.0
___/   /   /___/   /   /___/       SE—Standard Edition

 Statistics and Data Science       Copyright 1985-2023 StataCorp LLC
                                   StataCorp
                                   4905 Lakeway Drive
                                   College Station, Texas 77845 USA
                                   800-STATA-PC        https://www.stata.com
                                   979-696-4600        stata@stata.com

Stata license: Unlimited-user network, expiring 29 Jan 2026
Serial number: 401809303191
  Licensed to: Nicholas Tokay
               LSE

Notes:
      1. Stata is running in batch mode.
      2. Unicode is supported; see help unicode_advice.
      3. Maximum number of variables is set to 5,000 but can be increased;
          see help set_maxvar.

. do "C:\Users\tokay\Nouveau Dossier\Dropbox\HRR_InflDisaster\Replication\InfDi
> saster_RepPackage\functionsRA\_figures_master.do" 

. 
. // MASTER DO-FILE FOR FIGURES
. // Hilscher, Raviv, Reis "How likely is an inflation disaster?"
. clear

. 
. if "$home" == "" {
.     local wd = subinstr(c(pwd), "\", "/", .) 
.         global home "`wd'"
.         
. }

. 
. 
. *global DataStata "$home/DataforStata//Tables&Plots"
. * Go one folder up
. * Get parent directory manually
. local lastslash = strrpos("$home", "/")   // Find last slash position

. global home_parent = substr("$home", 1, `lastslash' - 1)   // Extract parent 
> directory

. global input "$home_parent/input"

. global figures "$home_parent/Figures"

. 
. 
. 
. // OPTION 2: which regions to run for, from {"EZ", "US"}
. local regions  "US" "EZ"

. 
. local updateIteration "2024_10Oct"

. 
. 
. // This sequence of programs create two end dta files:  EZ_allq and EZ_allm, 
. //  with all the data then used in paper. Some intermediate datasets are also
. //  created, EZ_ZQtails, EZ_ZNtails, EZ_YQtails, EZ_55tailsmonthly, EZ_55tail
> squarterly
. //  whichcombined would have many more variables
. foreach region of local regions {
  2. 
.     disp "`region'"
  3.     
.     clear all
  4.     // data & computing
.     do "$home/data_ZQtails.do" `region' `updateIteration'
  5.     do "$home/data_ZNtails.do" `region' `updateIteration'
  6.     do "$home/data_YQtails.do" `region' `updateIteration'
  7.     do "$home/data_55tails.do" `region'
  8.     
.     // merge
.     do "$home/data_mergem.do" `region'
  9. }
US

. *****************************************************************************
> ***
. * CREATE ZQTAILS DATASET, USING Q DISTS, WITH ZC TAIL PROBABILITIES PER MONTH
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> cd `dir'
> local region = "EZ"     // set region US or EZ
> local updateIteration "Mar2022"
> */
. 
. local region `1'

. local updateIteration `2'

. 
. *Redo monthly data and drop empty variables
. u "$input/`region'_dist_Z_monthly", clear

. 
. gen day = day(date_stata)

. gen month = month(date_stata)

. gen year = year(date_stata)

. sort year month day

.     collapse (first) date_stata, by(year month)

.     keep date_stata

.     merge 1:m date using "$input/`region'_dist_Z_monthly.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            22,806  (_merge==3)
    -----------------------------------------

.     keep if _merge == 3
(0 observations deleted)

.     drop _merge

. *drop I J K L M N O
. 
. // Generate 5-year cumulative tails
. generate tails_5y = frequency if dist_identifier=="ZQ5" 
(19,026 missing values generated)

. 
. generate uptails_5y = tails_5y if support>=.04
(21,546 missing values generated)

. egen tail4_5y = total(uptails_5y), by(date_stata)

. replace uptails_5y=. if support<0.05
(360 real changes made, 360 to missing)

. egen tail5_5y = total(uptails_5y), by(date_stata)

. drop uptails_5y

. 
. generate dotails_5y = tails_5y if support<=0
(21,546 missing values generated)

. egen tail0_5y = total(dotails_5y), by(date_stata)

. replace dotails_5y=. if support>-0.01
(540 real changes made, 540 to missing)

. egen tailm1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. generate dotails_5y = tails_5y if support<=0.01
(21,366 missing values generated)

. egen tail1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. // Generate 5-year densities
. g q1_5y = tails_5y if support==0.01
(22,806 missing values generated)

. g q0_5y = tails_5y if support==0.0
(22,626 missing values generated)

. g q4_5y = tails_5y if support==0.04
(22,806 missing values generated)

. g q5_5y = tails_5y if support==0.05
(22,626 missing values generated)

. 
. drop tails_5y

. 
. // Generate 10-year cumulative tails
. generate tails_10y = frequency if dist_identifier=="ZQ10" 
(19,026 missing values generated)

. 
. generate uptails_10y = tails_10y if support>=.04
(21,546 missing values generated)

. egen tail4_10y = total(uptails_10y), by(date_stata)

. replace uptails_10y=. if support<0.05
(360 real changes made, 360 to missing)

. egen tail5_10y = total(uptails_10y), by(date_stata)

. drop uptails_10y

. 
. generate dotails_10y = tails_10y if support<=0
(21,546 missing values generated)

. egen tail0_10y = total(dotails_10y), by(date_stata)

. replace dotails_10y=. if support>-0.01
(540 real changes made, 540 to missing)

. egen tailm1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. generate dotails_10y = tails_10y if support<=0.01
(21,366 missing values generated)

. egen tail1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. // Generate  10-year densities
. g q1_10y = tails_10y if support==0.01
(22,806 missing values generated)

. g q0_10y = tails_10y if support==0.0
(22,626 missing values generated)

. g q4_10y = tails_10y if support==0.04
(22,806 missing values generated)

. g q5_10y = tails_10y if support==0.05
(22,626 missing values generated)

. 
. drop tails_10y

. 
. // Collapse and drop all other variables
. collapse date tail4_5y tail1_5y tail5_5y tailm1_5y tail0_5y tail4_10y tail5_1
> 0y tail1_10y tailm1_10y tail0_10y q4_5y q4_10y q5_5y q5_10y q1_5y q1_10y q0_5
> y q0_10y, by(date_stata)

. 
. // Generate year month variable
. g date_ym = mofd(date_stata)

. format date_ym %tm

. 
. //Create good labels
. label data "Dataset of tail probabilities, at 5- and 10-year horizon, at -1,0
> ,4,5"

. label variable tail4_5y         "Tail CDF: 1 - Q(pi^5=4)"

. label variable tail1_5y         "Tail CDF: Q(pi^5=1)"

. label variable tail5_5y         "Tail CDF: 1 - Q(pi^5=5)"

. label variable tailm1_5y        "Tail CDF: Q(pi^5=-1)"

. label variable tail0_5y         "Tail CDF: Q(pi^5=0)"

. label variable tail4_10y        "Tail CDF: 1 - Q(pi^10=4)"

. label variable tail5_10y        "Tail CDF: 1 - Q(pi^10=5)"

. label variable tail1_10y        "Tail CDF: Q(pi^10=1)"

. label variable tailm1_10y       "Tail CDF: 1 - Q(pi^10=-1)"

. label variable tail0_10y        "Tail CDF: 1 - Q(pi^10=0)"

. label variable q4_5y            "PDF: q(pi^5=4)"

. label variable q4_10y           "PDF: q(pi^10=4)"

. label variable q5_5y            "PDF: q(pi^5=5)"

. label variable q5_10y           "PDF: q(pi^10=5)"

. label variable q1_5y            "PDF: q(pi^5=1)"

. label variable q1_10y           "PDF: q(pi^10=1)"

. label variable q0_5y            "PDF: q(pi^5=0)"

. label variable q0_10y           "PDF: q(pi^10=0)"

. label variable date_ym          "Date in plot format"

. label variable date_stata       "Date in Stata format"

. label variable date     "Date in original format"

. order date_ym , after(date_stata)

. 
. // save it
. sleep 100

. save "$input/`region'_ZQtails.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_ZQtails.dta saved

. 
end of do-file

. *****************************************************************************
> ***
. * CREATE ZNTAILS DATASET, USING N DISTS, WITH ZC TAIL PROBABILITIES PER MONTH
>  -- bad programming because really copy and paste of Z program but ok
.  
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> cd `dir'
> local region = "US"     // set region US or EZ
> local updateIteration "Mar2022"
> */
. 
. local region `1'

. local updateIteration `2'

. 
. *Redo monthly choice to make sure it is, and drop empty variables
. u "$input/`region'_dist_Z_monthly", clear

. 
. gen day = day(date_stata)

. gen month = month(date_stata)

. gen year = year(date_stata)

. sort year month day

.     collapse (first) date_stata, by(year month)

.     keep date_stata

.     merge 1:m date using "$input/`region'_dist_Z_monthly.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            22,806  (_merge==3)
    -----------------------------------------

.     keep if _merge == 3
(0 observations deleted)

.     drop _merge

. *drop I J K L M N O
. 
. // Generate 5-year cumulative tails
. generate tails_5y = frequency if dist_identifier=="ZN5" 
(19,026 missing values generated)

. 
. generate uptails_5y = tails_5y if support>=.04
(21,546 missing values generated)

. egen Ntail4_5y = total(uptails_5y), by(date_stata)

. replace uptails_5y=. if support<0.05
(360 real changes made, 360 to missing)

. egen Ntail5_5y = total(uptails_5y), by(date_stata)

. drop uptails_5y

. 
. generate dotails_5y = tails_5y if support<=0
(21,546 missing values generated)

. egen Ntail0_5y = total(dotails_5y), by(date_stata)

. replace dotails_5y=. if support>-0.01
(540 real changes made, 540 to missing)

. egen Ntailm1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. generate dotails_5y = tails_5y if support<=0.01
(21,366 missing values generated)

. egen Ntail1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. // Generate 5-year densities
. g nm1_5y = tails_5y if support==-0.01
(22,806 missing values generated)

. g n1_5y = tails_5y if support==0.01
(22,806 missing values generated)

. g n0_5y = tails_5y if support==0.0
(22,626 missing values generated)

. g n4_5y = tails_5y if support==0.04
(22,806 missing values generated)

. g n5_5y = tails_5y if support==0.05
(22,626 missing values generated)

. 
. drop tails_5y

. 
. // Generate 10-year cumulative tails
. generate tails_10y = frequency if dist_identifier=="ZN10" 
(19,026 missing values generated)

. 
. generate uptails_10y = tails_10y if support>=.04
(21,546 missing values generated)

. egen Ntail4_10y = total(uptails_10y), by(date_stata)

. replace uptails_10y=. if support<0.05
(360 real changes made, 360 to missing)

. egen Ntail5_10y = total(uptails_10y), by(date_stata)

. drop uptails_10y

. 
. generate dotails_10y = tails_10y if support<=0
(21,546 missing values generated)

. egen Ntail0_10y = total(dotails_10y), by(date_stata)

. replace dotails_10y=. if support>-0.01
(540 real changes made, 540 to missing)

. egen Ntailm1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. generate dotails_10y = tails_10y if support<=0.01
(21,366 missing values generated)

. egen Ntail1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. // Generate 10-year densities
. g nm1_10y = tails_10y if support==-0.01
(22,806 missing values generated)

. g n0_10y = tails_10y if support==0.0
(22,626 missing values generated)

. g n1_10y = tails_10y if support==0.01
(22,806 missing values generated)

. g n4_10y = tails_10y if support==0.04
(22,806 missing values generated)

. g n5_10y = tails_10y if support==0.05
(22,626 missing values generated)

. 
. drop tails_10y

. 
. // Collapse and drop all other variables
. collapse date Ntail4_5y Ntail5_5y Ntailm1_5y Ntail0_5y Ntail4_10y Ntail5_10y 
> Ntailm1_10y Ntail0_10y n4_5y n4_10y n5_5y n5_10y nm1_5y nm1_10y n0_5y n0_10y 
>  Ntail1_5y Ntail1_10y n1_5y n1_10y , by(date_stata)

. 
. 
. // Generate year month variable
. g date_ym = mofd(date_stata)

. format date_ym %tm

. 
. // save it
. sleep 100

. save "$input/`region'_ZNtails.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_ZNtails.dta saved

. 
end of do-file

. *****************************************************************************
> ***
. * CREATE QY TAILS DATASET, USING Q DISTS, WITH Y TAIL PROBABILITIES PER MONTH
.  
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> cd `dir'
> local region = "US"     // set region US or EZ
> local updateIteration "Mar2022"
> */
. 
. local region `1'

. local updateIteration `2'

. 
. *Redo monthly choice to make sure it is, and drop empty variables
. u "$input/`region'_dist_Y_monthly", clear

. 
. gen day = day(date_stata)

. gen month = month(date_stata)

. gen year = year(date_stata)

. sort year month day

.     collapse (first) date_stata, by(year month)

.     keep date_stata

.     merge 1:m date using "$input/`region'_dist_Y_monthly.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            49,590  (_merge==3)
    -----------------------------------------

.     keep if _merge == 3
(0 observations deleted)

.     drop _merge

. *drop I J K L M N O
. 
. *****************************************************************************
> ***
. 
. // Generate yoy upper tails
. generate y6y = frequency if dist_identifier=="YQ6" 
(44,631 missing values generated)

. generate uptails_6y = y6y if support>=.04
(48,051 missing values generated)

. egen Ytail4_y6 = total(uptails_6y), by(date_stata)

. replace uptails_6y=. if support<0.05
(342 real changes made, 342 to missing)

. egen Ytail5_y6 = total(uptails_6y), by(date_stata)

. drop uptails_6y y6y

. 
. generate y7y = frequency if dist_identifier=="YQ7" 
(44,631 missing values generated)

. generate uptails_7y = y7y if support>=.04
(48,051 missing values generated)

. egen Ytail4_y7 = total(uptails_7y), by(date_stata)

. replace uptails_7y=. if support<0.05
(342 real changes made, 342 to missing)

. egen Ytail5_y7 = total(uptails_7y), by(date_stata)

. drop uptails_7y y7y

. 
. generate y8y = frequency if dist_identifier=="YQ8" 
(44,631 missing values generated)

. generate uptails_8y = y8y if support>=.04
(48,051 missing values generated)

. egen Ytail4_y8 = total(uptails_8y), by(date_stata)

. replace uptails_8y=. if support<0.05
(342 real changes made, 342 to missing)

. egen Ytail5_y8 = total(uptails_8y), by(date_stata)

. drop uptails_8y y8y

. 
. generate y9y = frequency if dist_identifier=="YQ9" 
(44,631 missing values generated)

. generate uptails_9y = y9y if support>=.04
(48,051 missing values generated)

. egen Ytail4_y9 = total(uptails_9y), by(date_stata)

. replace uptails_9y=. if support<0.05
(342 real changes made, 342 to missing)

. egen Ytail5_y9 = total(uptails_9y), by(date_stata)

. drop uptails_9y y9y

. 
. generate y10y = frequency if dist_identifier=="YQ10" 
(44,631 missing values generated)

. generate uptails_10y = y10y if support>=.04
(48,051 missing values generated)

. egen Ytail4_y10 = total(uptails_10y), by(date_stata)

. replace uptails_10y=. if support<0.05
(342 real changes made, 342 to missing)

. egen Ytail5_y10 = total(uptails_10y), by(date_stata)

. drop uptails_10y y10y

. 
. // Generate yoy bottom tails
. generate y6y = frequency if dist_identifier=="YQ6" 
(44,631 missing values generated)

. generate dotails_6y = y6y if support<=0
(47,367 missing values generated)

. egen Ytail0_y6 = total(dotails_6y), by(date_stata)

. replace dotails_6y=. if support>-0.01
(513 real changes made, 513 to missing)

. egen Ytailm1_y6 = total(dotails_6y), by(date_stata)

. drop dotails_6y y6y

. 
. generate y7y = frequency if dist_identifier=="YQ7" 
(44,631 missing values generated)

. generate dotails_7y = y7y if support<=0
(47,367 missing values generated)

. egen Ytail0_y7 = total(dotails_7y), by(date_stata)

. replace dotails_7y=. if support>-0.01
(513 real changes made, 513 to missing)

. egen Ytailm1_y7 = total(dotails_7y), by(date_stata)

. drop dotails_7y y7y

. 
. generate y8y = frequency if dist_identifier=="YQ8" 
(44,631 missing values generated)

. generate dotails_8y = y8y if support<=0
(47,367 missing values generated)

. egen Ytail0_y8 = total(dotails_8y), by(date_stata)

. replace dotails_8y=. if support>-0.01
(513 real changes made, 513 to missing)

. egen Ytailm1_y8 = total(dotails_8y), by(date_stata)

. drop dotails_8y y8y

. 
. generate y9y = frequency if dist_identifier=="YQ9" 
(44,631 missing values generated)

. generate dotails_9y = y9y if support<=0
(47,367 missing values generated)

. egen Ytail0_y9 = total(dotails_9y), by(date_stata)

. replace dotails_9y=. if support>-0.01
(513 real changes made, 513 to missing)

. egen Ytailm1_y9 = total(dotails_9y), by(date_stata)

. drop dotails_9y y9y

. 
. generate y10y = frequency if dist_identifier=="YQ10" 
(44,631 missing values generated)

. generate dotails_10y = y10y if support<=0
(47,367 missing values generated)

. egen Ytail0_y10 = total(dotails_10y), by(date_stata)

. replace dotails_10y=. if support>-0.01
(513 real changes made, 513 to missing)

. egen Ytailm1_y10 = total(dotails_10y), by(date_stata)

. drop dotails_10y y10y

. 
. // Collapse and drop all other variables
. collapse date Ytail4_y6 Ytail4_y7 Ytail4_y8 Ytail4_y9 Ytail4_y10 Ytail5_y6 Yt
> ail5_y7 Ytail5_y8 Ytail5_y9 Ytail5_y10 Ytail0_y6 Ytail0_y7 Ytail0_y8 Ytail0_y
> 9 Ytail0_y10 Ytailm1_y6 Ytailm1_y7 Ytailm1_y8 Ytailm1_y9 Ytailm1_y10, by(date
> _stata)

. 
. // Generate year month variable
. g date_ym = mofd(date_stata)

. format date_ym %tm

. 
. //Create good labels
. label data "Dataset of tail probabilities, at 5- and 10-year horizon, at -1,0
> ,4,5"

. label variable Ytail4_y6        "YTail CDF: 1 - Q(pi_6=4)"

. label variable Ytail4_y7        "YTail CDF: 1 - Q(pi_7=4)"

. label variable Ytail4_y8        "YTail CDF: 1 - Q(pi_8=4)"

. label variable Ytail4_y9        "YTail CDF: 1 - Q(pi_9=4)"

. label variable Ytail4_y10       "YTail CDF: 1 - Q(pi_10=4)"

. label variable Ytail5_y6        "YTail CDF: 1 - Q(pi_6=5)"

. label variable Ytail5_y7        "YTail CDF: 1 - Q(pi_7=5)"

. label variable Ytail5_y8        "YTail CDF: 1 - Q(pi_8=5)"

. label variable Ytail5_y9        "YTail CDF: 1 - Q(pi_9=5)"

. label variable Ytail5_y10       "YTail CDF: 1 - Q(pi_10=5)"

. label variable Ytail0_y6        "YTail CDF: Q(pi_6=0)"

. label variable Ytail0_y7        "YTail CDF: Q(pi_7=0)"

. label variable Ytail0_y8        "YTail CDF: Q(pi_8=0)"

. label variable Ytail0_y9        "YTail CDF: Q(pi_9=0)"

. label variable Ytail0_y10       "YTail CDF: Q(pi_10=0)"

. label variable Ytailm1_y6       "YTail CDF: Q(pi_6=-1)"

. label variable Ytailm1_y7       "YTail CDF: Q(pi_7=-1)"

. label variable Ytailm1_y8       "YTail CDF: Q(pi_8=-1)"

. label variable Ytailm1_y9       "YTail CDF: Q(pi_9=-1)"

. label variable Ytailm1_y10      "YTail CDF: Q(pi_10=-1)"

. label variable date_ym          "Date in plot format"

. label variable date_stata       "Date in Stata format"

. label variable date     "Date in original format"

. order date_ym , after(date_stata)

. 
. // save it
. sleep 100

. save "$input/`region'_YQtails.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_YQtails.dta saved

. 
end of do-file

. *Program to create dta file for model on the quarterly data
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "EZ"     // set region US or EZ
> */
. 
. local region `1'

. 
. * Create dataset with model estimates
. ******************************
. *Read off model estimates
. clear

. import excel "$input/prob_avginfl_monthly.xlsx", sheet("`region'_model_101_mo
> nth") cellrange(A2) firstrow clear
(10 vars, 166 obs)

. 
. generate date_ym = ym(year, month)

. format %tm date_ym

. order date_ym

. 
. label variable y5y_def_0_4              "Model 101 estimate of deflation"

. label variable y5y_hyp_0_4              "Model 101 estimate of infation"

. label variable y5y_def_m1_5     "Model 101 estimate of serious deflation"

. label variable y5y_hyp_m1_5     "Model 101 estimate of serious infation"

. drop next*

.   // Daniel prodcued these in simulations, not used right now
. 
. rename y5y_def_0_4 tail0_5y5y

. rename y5y_hyp_0_4 tail4_5y5y

. rename y5y_def_m1_5 tailm1_5y5y

. rename y5y_hyp_m1_5 tail5_5y5y

. 
. sleep 100

. save "$input/`region'_55tails_monthly.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_55tails_monthly.dta saved

. 
end of do-file

. *Program to merge all dta files in one big dataset
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "US"     // set region US or EZ
> */
. 
. local region `1'

. 
. * Create dataset with model estimates
. ******************************
. *Read off Daniel estimates
. clear

. u "$input/`region'_55tails_monthly"

. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_allm.dta saved

. 
. *Merge with Q tails
. clear

. u "$input/`region'_ZQtails"
(Dataset of tail probabilities, at 5- and 10-year horizon, at -1,0,4,5)

. merge 1:1 date_ym using "$input/`region'_allm"

    Result                      Number of obs
    -----------------------------------------
    Not matched                            15
        from master                        15  (_merge==1)
        from using                          0  (_merge==2)

    Matched                               166  (_merge==3)
    -----------------------------------------

. drop _merge q*

. order date_stata date_ym date

. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_allm.dta saved

. 
. *Merge with N tails
. clear

. u "$input/`region'_ZNtails"

. merge 1:1 date_ym using "$input/`region'_allm"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               181  (_merge==3)
    -----------------------------------------

. drop _merge n*

. order date_stata date_ym date

. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_allm.dta saved

. 
. *Merge with YQ tails
. clear

. u "$input/`region'_allm"

. merge 1:1 date_ym using "$input/`region'_YQtails"

    Result                      Number of obs
    -----------------------------------------
    Not matched                            11
        from master                        11  (_merge==1)
        from using                          0  (_merge==2)

    Matched                               170  (_merge==3)
    -----------------------------------------

. drop _merge

. order date_stata date_ym date

. g Ytail4_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5
(11 missing values generated)

. g Ytail5_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5
(11 missing values generated)

. g Ytail0_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5
(11 missing values generated)

. g Ytailm1_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5
(11 missing values generated)

. label variable Ytail4_avg       "Average yoy forward >4"

. label variable Ytail5_avg       "Average yoy forward >5"

. label variable Ytail0_avg       "Average yoy forward <0"

. label variable Ytailm1_avg      "Average yoy forward <m1"

. 
. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_allm.dta saved

. 
. *Risk-adjusted estimates: constant ones
. ******************************
. 
. *Merge with Riskpremia 
.   //clear
.   //u RiskAdjustments.dta
.   //merge 1:1 date_ym using `region'_allm
.   //drop _merge
.   //order date_stata date_ym date
. do "$home/data_RiskAdjustments.do"

. ****************************************************
. *Risk factor for different methods
. ****************************************************
. 
. /*
> *If run as standalone, wouold have to create a dataseries of the desired size
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> */
. 
. *****************************
. * Set key parameters
. *pick method
. scalar method   =       6       // pick method 2.3 from R files

. scalar gamma    =       3       // risk aversion coefficient

. 
. *unconditions probability of output disaster
. scalar pyd              = 0.013         // probability of output disaster fro
> m Barro, R file too

. scalar pyd = (1- (1-pyd)^5) // 5-year terms

. 
. * 2) Run the newly created pareto_matrix.do
. do pareto_matrix.do

. matrix Pareto = (0.213,0.207,0.132,0.206,0.213,0.134 ///
>  \ 0.167,0.18,0.213,0.169,0.186,0.2 ///
>  \ 1.04,1.03,1.04,1.03,1.03,1.03 ///
>  \ 5.73,5.7,6.77,6.11,6.67,6.38)

. matrix rownames Pareto = Prob_pid_unc Prob_yd_cond_pid z0 alpha

. matrix list Pareto

Pareto[4,6]
                c1    c2    c3    c4    c5    c6
Prob_pid_unc  .213  .207  .132  .206  .213  .134
Prob_yd_co~d  .167   .18  .213  .169  .186    .2
          z0  1.04  1.03  1.04  1.03  1.03  1.03
       alpha  5.73   5.7  6.77  6.11  6.67  6.38

. 
. 
end of do-file

. 
. 
. *****************************
. *Risk factors for pooled sample
. *  Read off fror R printout for 6 columns of methods: punc, pcond, z0, alpha
. *       matrix Pareto = (0.213,0.207,0.132,0.206,0.213,0.134 ///
> *                               \ 0.167,0.18,0.213,0.169,0.186,0.200 ///
> *                               \ 1.04,1.03,1.04,1.03,1.03,1.03 ///
> *                               \ 5.73,5.7,6.77,6.11,6.67,6.38)
. * rownames Pareto = Prob_pid_unc Prob_yd_cond_pid z0 alpha
. *matrix list Pareto
. 
. *  Calculate adjustments using formula
. scalar z0 = Pareto[3,method] 

. scalar alpha = Pareto[4,method]

. g md = (alpha/(alpha-gamma))*z0^gamma  //formula for m_d

. g ptilde = Pareto[2,method]                // prob (y_d / pi_d)

. g RiskFactor = 1/(1 + ptilde*(md-1))   //formula from paper

. label variable RiskFactor "Risk factor, pooled constant"

. summ RiskFactor ptilde md                  // reads to be 0.82

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
  RiskFactor |        181    .8247283           0   .8247283   .8247283
      ptilde |        181          .2           0         .2         .2
          md |        181    2.062603           0   2.062603   2.062603

. 
. *  Calculate time varying one using second formula -- this actually did not e
> nd up getting used
. * g pinvtilde =  (Pareto[1,method] / pyd )*ptilde // this is prob(pi_d/y_d)
. 
. *clean repeated scalars
. scalar drop z0 alpha 

. 
. *****************************
. *Risk factors for high inflation sample
. *  Read off fror R printout for 6 columns of methods: punc, pcond, z0, alpha
. matrix Paretopos = (0.133,0.129,0.063,0.124,0.131,0.057 ///
>                                 \ 0.203,0.23,0.303,0.227,0.251,0.356 ///
>                                 \ 1.07, 1.03, 1.05, 1.03, 1.03, 1.03 ///
>                                 \ 5.4, 5.11, 5.73, 5.4, 6.09, 5.45)

. matrix rownames Paretopos = Prob_pid_unc Prob_yd_cond_pid z0 alpha

. matrix list Paretopos

Paretopos[4,6]
                c1    c2    c3    c4    c5    c6
Prob_pid_unc  .133  .129  .063  .124  .131  .057
Prob_yd_co~d  .203   .23  .303  .227  .251  .356
          z0  1.07  1.03  1.05  1.03  1.03  1.03
       alpha   5.4  5.11  5.73   5.4  6.09  5.45

. 
. *calculate adjustments using formula
. scalar z0 = Paretopos[3,method] 

. scalar alpha = Paretopos[4,method]

. g md_pos = (alpha/(alpha-gamma))*z0^gamma

. g ptilde_pos = Paretopos[2,method]

. g RiskFactor_pos = 1/(1 + ptilde_pos*(md_pos-1))

. summ RiskFactor_pos ptilde_pos md_pos  // reads to be 0.65

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
RiskFactor~s |        181    .6625366           0   .6625366   .6625366
  ptilde_pos |        181        .356           0       .356       .356
      md_pos |        181     2.43076           0    2.43076    2.43076

. label variable RiskFactor_pos "Risk factor, high-inflation constant"

. 
. *  Calculate time varying one using second formula
. * g pinvtilde_pos =  (Paretopos[1,method] / pyd )*ptilde_pos // this is prob(
> pi_d/y_d)
. 
. *clean repeated scalars
. scalar drop z0 alpha 

. 
. *****************************
. *Risk factors for deflation sample
. *  Read off fror R printout for 6 columns of methods: punc, pcond, z0, alpha
. matrix Paretoneg = (0.105,0.102,0.078,0.105,0.108,0.086 ///
>                                 \ 0.121,0.114,0.142,0.085,0.085,0.085 ///
>                                 \ 1.04, 1.03, 1.04, 1.06, 1.06, 1.06 ///
>                                 \ 10.84, 8.62, 11.55, 15.18, 15.18, 15.18)

. matrix rownames Paretoneg = Prob_pid_unc Prob_yd_cond_pid z0 alpha

. matrix list Paretoneg

Paretoneg[4,6]
                 c1     c2     c3     c4     c5     c6
Prob_pid_unc   .105   .102   .078   .105   .108   .086
Prob_yd_co~d   .121   .114   .142   .085   .085   .085
          z0   1.04   1.03   1.04   1.06   1.06   1.06
       alpha  10.84   8.62  11.55  15.18  15.18  15.18

. 
. *calculate adjustments using formula
. scalar alpha = Paretoneg[4,method]

. scalar z0 = Paretoneg[3,method] 

. g md_neg = (alpha/(alpha-gamma))*z0^gamma

. g ptilde_neg = Paretoneg[2,method]

. g RiskFactor_neg = 1/(1 + ptilde_neg*(md_neg-1))

. summ RiskFactor_neg ptilde_neg md_neg  // reads to be 0.96

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
RiskFactor~g |        181    .9604566           0   .9604566   .9604566
  ptilde_neg |        181        .085           0       .085       .085
      md_neg |        181     1.48437           0    1.48437    1.48437

. label variable RiskFactor_neg "Risk factor, deflation constant"

. 
. *  Calculate time varying one using second formula
. * g pinvtilde_neg =  (Paretoneg[1,method] / pyd )*ptilde_neg // this is prob(
> pi_d/y_d)
. 
. *clean repeated scalars
. scalar drop z0 alpha 

. 
. /*. 
> *Run this bit only if using as standalone
> sleep 100
> save RiskAdjustments, replace

end of do-file

. 
. *do ./data_RiskAdjustments.do
. sleep 500

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_allm.dta saved

. 
. clear

. u "$input/`region'_allm"

. 
. *10 year numbers, tails, with risk factor
. g p4_10y_pool_c = tail4_10y * RiskFactor

. g p4_10y_high_c = tail4_10y * RiskFactor_pos

. g p5_10y_pool_c = tail5_10y * RiskFactor

. g p5_10y_high_c = tail5_10y * RiskFactor_pos

. g p0_10y_low_c = tail0_10y * RiskFactor_neg

. g p0_10y_pool_c = tail0_10y * RiskFactor

. g pm1_10y_pool_c = tailm1_10y * RiskFactor

. g pm1_10y_low_c = tailm1_10y * RiskFactor_neg

. 
. *5 year numbers, tails, with risk factor
. g p4_5y_pool_c = tail4_5y * RiskFactor

. g p4_5y_high_c = tail4_5y * RiskFactor_pos

. g p5_5y_pool_c = tail5_5y * RiskFactor

. g p5_5y_high_c = tail5_5y * RiskFactor_pos

. g p0_5y_low_c = tail0_5y * RiskFactor_neg

. g p0_5y_pool_c = tail0_5y * RiskFactor

. g pm1_5y_pool_c = tailm1_5y * RiskFactor

. g pm1_5y_low_c = tailm1_5y * RiskFactor_neg

. 
. *5y5y numbers, tails, with risk factor
. g p4_5y5y_pool_c = tail4_5y5y * RiskFactor
(15 missing values generated)

. g p4_5y5y_high_c = tail4_5y5y * RiskFactor_pos
(15 missing values generated)

. g p5_5y5y_pool_c = tail5_5y5y * RiskFactor
(15 missing values generated)

. g p5_5y5y_high_c = tail5_5y5y * RiskFactor_pos
(15 missing values generated)

. g p0_5y5y_low_c = tail0_5y5y * RiskFactor_neg
(15 missing values generated)

. g p0_5y5y_pool_c = tail0_5y5y * RiskFactor
(15 missing values generated)

. g pm1_5y5y_pool_c = tailm1_5y5y * RiskFactor
(15 missing values generated)

. g pm1_5y5y_low_c = tailm1_5y5y * RiskFactor_neg
(15 missing values generated)

. 
. sleep 500

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_allm.dta saved

. 
end of do-file
EZ

. *****************************************************************************
> ***
. * CREATE ZQTAILS DATASET, USING Q DISTS, WITH ZC TAIL PROBABILITIES PER MONTH
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> cd `dir'
> local region = "EZ"     // set region US or EZ
> local updateIteration "Mar2022"
> */
. 
. local region `1'

. local updateIteration `2'

. 
. *Redo monthly data and drop empty variables
. u "$input/`region'_dist_Z_monthly", clear

. 
. gen day = day(date_stata)

. gen month = month(date_stata)

. gen year = year(date_stata)

. sort year month day

.     collapse (first) date_stata, by(year month)

.     keep date_stata

.     merge 1:m date using "$input/`region'_dist_Z_monthly.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            21,042  (_merge==3)
    -----------------------------------------

.     keep if _merge == 3
(0 observations deleted)

.     drop _merge

. *drop I J K L M N O
. 
. // Generate 5-year cumulative tails
. generate tails_5y = frequency if dist_identifier=="ZQ5" 
(17,535 missing values generated)

. 
. generate uptails_5y = tails_5y if support>=.04
(19,873 missing values generated)

. egen tail4_5y = total(uptails_5y), by(date_stata)

. replace uptails_5y=. if support<0.05
(501 real changes made, 501 to missing)

. egen tail5_5y = total(uptails_5y), by(date_stata)

. drop uptails_5y

. 
. generate dotails_5y = tails_5y if support<=0
(19,873 missing values generated)

. egen tail0_5y = total(dotails_5y), by(date_stata)

. replace dotails_5y=. if support>-0.01
(334 real changes made, 334 to missing)

. egen tailm1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. generate dotails_5y = tails_5y if support<=0.01
(19,539 missing values generated)

. egen tail1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. // Generate 5-year densities
. g q1_5y = tails_5y if support==0.01
(20,875 missing values generated)

. g q0_5y = tails_5y if support==0.0
(20,875 missing values generated)

. g q4_5y = tails_5y if support==0.04
(20,875 missing values generated)

. g q5_5y = tails_5y if support==0.05
(21,042 missing values generated)

. 
. drop tails_5y

. 
. // Generate 10-year cumulative tails
. generate tails_10y = frequency if dist_identifier=="ZQ10" 
(17,535 missing values generated)

. 
. generate uptails_10y = tails_10y if support>=.04
(19,873 missing values generated)

. egen tail4_10y = total(uptails_10y), by(date_stata)

. replace uptails_10y=. if support<0.05
(501 real changes made, 501 to missing)

. egen tail5_10y = total(uptails_10y), by(date_stata)

. drop uptails_10y

. 
. generate dotails_10y = tails_10y if support<=0
(19,873 missing values generated)

. egen tail0_10y = total(dotails_10y), by(date_stata)

. replace dotails_10y=. if support>-0.01
(334 real changes made, 334 to missing)

. egen tailm1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. generate dotails_10y = tails_10y if support<=0.01
(19,539 missing values generated)

. egen tail1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. // Generate  10-year densities
. g q1_10y = tails_10y if support==0.01
(20,875 missing values generated)

. g q0_10y = tails_10y if support==0.0
(20,875 missing values generated)

. g q4_10y = tails_10y if support==0.04
(20,875 missing values generated)

. g q5_10y = tails_10y if support==0.05
(21,042 missing values generated)

. 
. drop tails_10y

. 
. // Collapse and drop all other variables
. collapse date tail4_5y tail1_5y tail5_5y tailm1_5y tail0_5y tail4_10y tail5_1
> 0y tail1_10y tailm1_10y tail0_10y q4_5y q4_10y q5_5y q5_10y q1_5y q1_10y q0_5
> y q0_10y, by(date_stata)

. 
. // Generate year month variable
. g date_ym = mofd(date_stata)

. format date_ym %tm

. 
. //Create good labels
. label data "Dataset of tail probabilities, at 5- and 10-year horizon, at -1,0
> ,4,5"

. label variable tail4_5y         "Tail CDF: 1 - Q(pi^5=4)"

. label variable tail1_5y         "Tail CDF: Q(pi^5=1)"

. label variable tail5_5y         "Tail CDF: 1 - Q(pi^5=5)"

. label variable tailm1_5y        "Tail CDF: Q(pi^5=-1)"

. label variable tail0_5y         "Tail CDF: Q(pi^5=0)"

. label variable tail4_10y        "Tail CDF: 1 - Q(pi^10=4)"

. label variable tail5_10y        "Tail CDF: 1 - Q(pi^10=5)"

. label variable tail1_10y        "Tail CDF: Q(pi^10=1)"

. label variable tailm1_10y       "Tail CDF: 1 - Q(pi^10=-1)"

. label variable tail0_10y        "Tail CDF: 1 - Q(pi^10=0)"

. label variable q4_5y            "PDF: q(pi^5=4)"

. label variable q4_10y           "PDF: q(pi^10=4)"

. label variable q5_5y            "PDF: q(pi^5=5)"

. label variable q5_10y           "PDF: q(pi^10=5)"

. label variable q1_5y            "PDF: q(pi^5=1)"

. label variable q1_10y           "PDF: q(pi^10=1)"

. label variable q0_5y            "PDF: q(pi^5=0)"

. label variable q0_10y           "PDF: q(pi^10=0)"

. label variable date_ym          "Date in plot format"

. label variable date_stata       "Date in Stata format"

. label variable date     "Date in original format"

. order date_ym , after(date_stata)

. 
. // save it
. sleep 100

. save "$input/`region'_ZQtails.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_ZQtails.dta saved

. 
end of do-file

. *****************************************************************************
> ***
. * CREATE ZNTAILS DATASET, USING N DISTS, WITH ZC TAIL PROBABILITIES PER MONTH
>  -- bad programming because really copy and paste of Z program but ok
.  
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> cd `dir'
> local region = "US"     // set region US or EZ
> local updateIteration "Mar2022"
> */
. 
. local region `1'

. local updateIteration `2'

. 
. *Redo monthly choice to make sure it is, and drop empty variables
. u "$input/`region'_dist_Z_monthly", clear

. 
. gen day = day(date_stata)

. gen month = month(date_stata)

. gen year = year(date_stata)

. sort year month day

.     collapse (first) date_stata, by(year month)

.     keep date_stata

.     merge 1:m date using "$input/`region'_dist_Z_monthly.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            21,042  (_merge==3)
    -----------------------------------------

.     keep if _merge == 3
(0 observations deleted)

.     drop _merge

. *drop I J K L M N O
. 
. // Generate 5-year cumulative tails
. generate tails_5y = frequency if dist_identifier=="ZN5" 
(17,535 missing values generated)

. 
. generate uptails_5y = tails_5y if support>=.04
(19,873 missing values generated)

. egen Ntail4_5y = total(uptails_5y), by(date_stata)

. replace uptails_5y=. if support<0.05
(501 real changes made, 501 to missing)

. egen Ntail5_5y = total(uptails_5y), by(date_stata)

. drop uptails_5y

. 
. generate dotails_5y = tails_5y if support<=0
(19,873 missing values generated)

. egen Ntail0_5y = total(dotails_5y), by(date_stata)

. replace dotails_5y=. if support>-0.01
(334 real changes made, 334 to missing)

. egen Ntailm1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. generate dotails_5y = tails_5y if support<=0.01
(19,539 missing values generated)

. egen Ntail1_5y = total(dotails_5y), by(date_stata)

. drop dotails_5y

. 
. // Generate 5-year densities
. g nm1_5y = tails_5y if support==-0.01
(21,042 missing values generated)

. g n1_5y = tails_5y if support==0.01
(20,875 missing values generated)

. g n0_5y = tails_5y if support==0.0
(20,875 missing values generated)

. g n4_5y = tails_5y if support==0.04
(20,875 missing values generated)

. g n5_5y = tails_5y if support==0.05
(21,042 missing values generated)

. 
. drop tails_5y

. 
. // Generate 10-year cumulative tails
. generate tails_10y = frequency if dist_identifier=="ZN10" 
(17,535 missing values generated)

. 
. generate uptails_10y = tails_10y if support>=.04
(19,873 missing values generated)

. egen Ntail4_10y = total(uptails_10y), by(date_stata)

. replace uptails_10y=. if support<0.05
(501 real changes made, 501 to missing)

. egen Ntail5_10y = total(uptails_10y), by(date_stata)

. drop uptails_10y

. 
. generate dotails_10y = tails_10y if support<=0
(19,873 missing values generated)

. egen Ntail0_10y = total(dotails_10y), by(date_stata)

. replace dotails_10y=. if support>-0.01
(334 real changes made, 334 to missing)

. egen Ntailm1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. generate dotails_10y = tails_10y if support<=0.01
(19,539 missing values generated)

. egen Ntail1_10y = total(dotails_10y), by(date_stata)

. drop dotails_10y

. 
. // Generate 10-year densities
. g nm1_10y = tails_10y if support==-0.01
(21,042 missing values generated)

. g n0_10y = tails_10y if support==0.0
(20,875 missing values generated)

. g n1_10y = tails_10y if support==0.01
(20,875 missing values generated)

. g n4_10y = tails_10y if support==0.04
(20,875 missing values generated)

. g n5_10y = tails_10y if support==0.05
(21,042 missing values generated)

. 
. drop tails_10y

. 
. // Collapse and drop all other variables
. collapse date Ntail4_5y Ntail5_5y Ntailm1_5y Ntail0_5y Ntail4_10y Ntail5_10y 
> Ntailm1_10y Ntail0_10y n4_5y n4_10y n5_5y n5_10y nm1_5y nm1_10y n0_5y n0_10y 
>  Ntail1_5y Ntail1_10y n1_5y n1_10y , by(date_stata)

. 
. 
. // Generate year month variable
. g date_ym = mofd(date_stata)

. format date_ym %tm

. 
. // save it
. sleep 100

. save "$input/`region'_ZNtails.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_ZNtails.dta saved

. 
end of do-file

. *****************************************************************************
> ***
. * CREATE QY TAILS DATASET, USING Q DISTS, WITH Y TAIL PROBABILITIES PER MONTH
.  
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> cd `dir'
> local region = "US"     // set region US or EZ
> local updateIteration "Mar2022"
> */
. 
. local region `1'

. local updateIteration `2'

. 
. *Redo monthly choice to make sure it is, and drop empty variables
. u "$input/`region'_dist_Y_monthly", clear

. 
. gen day = day(date_stata)

. gen month = month(date_stata)

. gen year = year(date_stata)

. sort year month day

.     collapse (first) date_stata, by(year month)

.     keep date_stata

.     merge 1:m date using "$input/`region'_dist_Y_monthly.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            48,720  (_merge==3)
    -----------------------------------------

.     keep if _merge == 3
(0 observations deleted)

.     drop _merge

. *drop I J K L M N O
. 
. *****************************************************************************
> ***
. 
. // Generate yoy upper tails
. generate y6y = frequency if dist_identifier=="YQ6" 
(43,848 missing values generated)

. generate uptails_6y = y6y if support>=.04
(47,208 missing values generated)

. egen Ytail4_y6 = total(uptails_6y), by(date_stata)

. replace uptails_6y=. if support<0.05
(336 real changes made, 336 to missing)

. egen Ytail5_y6 = total(uptails_6y), by(date_stata)

. drop uptails_6y y6y

. 
. generate y7y = frequency if dist_identifier=="YQ7" 
(43,848 missing values generated)

. generate uptails_7y = y7y if support>=.04
(47,208 missing values generated)

. egen Ytail4_y7 = total(uptails_7y), by(date_stata)

. replace uptails_7y=. if support<0.05
(336 real changes made, 336 to missing)

. egen Ytail5_y7 = total(uptails_7y), by(date_stata)

. drop uptails_7y y7y

. 
. generate y8y = frequency if dist_identifier=="YQ8" 
(43,848 missing values generated)

. generate uptails_8y = y8y if support>=.04
(47,208 missing values generated)

. egen Ytail4_y8 = total(uptails_8y), by(date_stata)

. replace uptails_8y=. if support<0.05
(336 real changes made, 336 to missing)

. egen Ytail5_y8 = total(uptails_8y), by(date_stata)

. drop uptails_8y y8y

. 
. generate y9y = frequency if dist_identifier=="YQ9" 
(43,848 missing values generated)

. generate uptails_9y = y9y if support>=.04
(47,208 missing values generated)

. egen Ytail4_y9 = total(uptails_9y), by(date_stata)

. replace uptails_9y=. if support<0.05
(336 real changes made, 336 to missing)

. egen Ytail5_y9 = total(uptails_9y), by(date_stata)

. drop uptails_9y y9y

. 
. generate y10y = frequency if dist_identifier=="YQ10" 
(43,848 missing values generated)

. generate uptails_10y = y10y if support>=.04
(47,208 missing values generated)

. egen Ytail4_y10 = total(uptails_10y), by(date_stata)

. replace uptails_10y=. if support<0.05
(336 real changes made, 336 to missing)

. egen Ytail5_y10 = total(uptails_10y), by(date_stata)

. drop uptails_10y y10y

. 
. // Generate yoy bottom tails
. generate y6y = frequency if dist_identifier=="YQ6" 
(43,848 missing values generated)

. generate dotails_6y = y6y if support<=0
(46,536 missing values generated)

. egen Ytail0_y6 = total(dotails_6y), by(date_stata)

. replace dotails_6y=. if support>-0.01
(504 real changes made, 504 to missing)

. egen Ytailm1_y6 = total(dotails_6y), by(date_stata)

. drop dotails_6y y6y

. 
. generate y7y = frequency if dist_identifier=="YQ7" 
(43,848 missing values generated)

. generate dotails_7y = y7y if support<=0
(46,536 missing values generated)

. egen Ytail0_y7 = total(dotails_7y), by(date_stata)

. replace dotails_7y=. if support>-0.01
(504 real changes made, 504 to missing)

. egen Ytailm1_y7 = total(dotails_7y), by(date_stata)

. drop dotails_7y y7y

. 
. generate y8y = frequency if dist_identifier=="YQ8" 
(43,848 missing values generated)

. generate dotails_8y = y8y if support<=0
(46,536 missing values generated)

. egen Ytail0_y8 = total(dotails_8y), by(date_stata)

. replace dotails_8y=. if support>-0.01
(504 real changes made, 504 to missing)

. egen Ytailm1_y8 = total(dotails_8y), by(date_stata)

. drop dotails_8y y8y

. 
. generate y9y = frequency if dist_identifier=="YQ9" 
(43,848 missing values generated)

. generate dotails_9y = y9y if support<=0
(46,536 missing values generated)

. egen Ytail0_y9 = total(dotails_9y), by(date_stata)

. replace dotails_9y=. if support>-0.01
(504 real changes made, 504 to missing)

. egen Ytailm1_y9 = total(dotails_9y), by(date_stata)

. drop dotails_9y y9y

. 
. generate y10y = frequency if dist_identifier=="YQ10" 
(43,848 missing values generated)

. generate dotails_10y = y10y if support<=0
(46,536 missing values generated)

. egen Ytail0_y10 = total(dotails_10y), by(date_stata)

. replace dotails_10y=. if support>-0.01
(504 real changes made, 504 to missing)

. egen Ytailm1_y10 = total(dotails_10y), by(date_stata)

. drop dotails_10y y10y

. 
. // Collapse and drop all other variables
. collapse date Ytail4_y6 Ytail4_y7 Ytail4_y8 Ytail4_y9 Ytail4_y10 Ytail5_y6 Yt
> ail5_y7 Ytail5_y8 Ytail5_y9 Ytail5_y10 Ytail0_y6 Ytail0_y7 Ytail0_y8 Ytail0_y
> 9 Ytail0_y10 Ytailm1_y6 Ytailm1_y7 Ytailm1_y8 Ytailm1_y9 Ytailm1_y10, by(date
> _stata)

. 
. // Generate year month variable
. g date_ym = mofd(date_stata)

. format date_ym %tm

. 
. //Create good labels
. label data "Dataset of tail probabilities, at 5- and 10-year horizon, at -1,0
> ,4,5"

. label variable Ytail4_y6        "YTail CDF: 1 - Q(pi_6=4)"

. label variable Ytail4_y7        "YTail CDF: 1 - Q(pi_7=4)"

. label variable Ytail4_y8        "YTail CDF: 1 - Q(pi_8=4)"

. label variable Ytail4_y9        "YTail CDF: 1 - Q(pi_9=4)"

. label variable Ytail4_y10       "YTail CDF: 1 - Q(pi_10=4)"

. label variable Ytail5_y6        "YTail CDF: 1 - Q(pi_6=5)"

. label variable Ytail5_y7        "YTail CDF: 1 - Q(pi_7=5)"

. label variable Ytail5_y8        "YTail CDF: 1 - Q(pi_8=5)"

. label variable Ytail5_y9        "YTail CDF: 1 - Q(pi_9=5)"

. label variable Ytail5_y10       "YTail CDF: 1 - Q(pi_10=5)"

. label variable Ytail0_y6        "YTail CDF: Q(pi_6=0)"

. label variable Ytail0_y7        "YTail CDF: Q(pi_7=0)"

. label variable Ytail0_y8        "YTail CDF: Q(pi_8=0)"

. label variable Ytail0_y9        "YTail CDF: Q(pi_9=0)"

. label variable Ytail0_y10       "YTail CDF: Q(pi_10=0)"

. label variable Ytailm1_y6       "YTail CDF: Q(pi_6=-1)"

. label variable Ytailm1_y7       "YTail CDF: Q(pi_7=-1)"

. label variable Ytailm1_y8       "YTail CDF: Q(pi_8=-1)"

. label variable Ytailm1_y9       "YTail CDF: Q(pi_9=-1)"

. label variable Ytailm1_y10      "YTail CDF: Q(pi_10=-1)"

. label variable date_ym          "Date in plot format"

. label variable date_stata       "Date in Stata format"

. label variable date     "Date in original format"

. order date_ym , after(date_stata)

. 
. // save it
. sleep 100

. save "$input/`region'_YQtails.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_YQtails.dta saved

. 
end of do-file

. *Program to create dta file for model on the quarterly data
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "EZ"     // set region US or EZ
> */
. 
. local region `1'

. 
. * Create dataset with model estimates
. ******************************
. *Read off model estimates
. clear

. import excel "$input/prob_avginfl_monthly.xlsx", sheet("`region'_model_101_mo
> nth") cellrange(A2) firstrow clear
(10 vars, 166 obs)

. 
. generate date_ym = ym(year, month)

. format %tm date_ym

. order date_ym

. 
. label variable y5y_def_0_4              "Model 101 estimate of deflation"

. label variable y5y_hyp_0_4              "Model 101 estimate of infation"

. label variable y5y_def_m1_5     "Model 101 estimate of serious deflation"

. label variable y5y_hyp_m1_5     "Model 101 estimate of serious infation"

. drop next*

.   // Daniel prodcued these in simulations, not used right now
. 
. rename y5y_def_0_4 tail0_5y5y

. rename y5y_hyp_0_4 tail4_5y5y

. rename y5y_def_m1_5 tailm1_5y5y

. rename y5y_hyp_m1_5 tail5_5y5y

. 
. sleep 100

. save "$input/`region'_55tails_monthly.dta", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_55tails_monthly.dta saved

. 
end of do-file

. *Program to merge all dta files in one big dataset
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "US"     // set region US or EZ
> */
. 
. local region `1'

. 
. * Create dataset with model estimates
. ******************************
. *Read off Daniel estimates
. clear

. u "$input/`region'_55tails_monthly"

. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_allm.dta saved

. 
. *Merge with Q tails
. clear

. u "$input/`region'_ZQtails"
(Dataset of tail probabilities, at 5- and 10-year horizon, at -1,0,4,5)

. merge 1:1 date_ym using "$input/`region'_allm"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             1
        from master                         1  (_merge==1)
        from using                          0  (_merge==2)

    Matched                               166  (_merge==3)
    -----------------------------------------

. drop _merge q*

. order date_stata date_ym date

. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_allm.dta saved

. 
. *Merge with N tails
. clear

. u "$input/`region'_ZNtails"

. merge 1:1 date_ym using "$input/`region'_allm"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               167  (_merge==3)
    -----------------------------------------

. drop _merge n*

. order date_stata date_ym date

. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_allm.dta saved

. 
. *Merge with YQ tails
. clear

. u "$input/`region'_allm"

. merge 1:1 date_ym using "$input/`region'_YQtails"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                               167  (_merge==3)
    -----------------------------------------

. drop _merge

. order date_stata date_ym date

. g Ytail4_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5

. g Ytail5_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5

. g Ytail0_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5

. g Ytailm1_avg = (Ytail4_y6+Ytail4_y7+Ytail4_y8+Ytail4_y9+Ytail4_y10)/5

. label variable Ytail4_avg       "Average yoy forward >4"

. label variable Ytail5_avg       "Average yoy forward >5"

. label variable Ytail0_avg       "Average yoy forward <0"

. label variable Ytailm1_avg      "Average yoy forward <m1"

. 
. sleep 100

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_allm.dta saved

. 
. *Risk-adjusted estimates: constant ones
. ******************************
. 
. *Merge with Riskpremia 
.   //clear
.   //u RiskAdjustments.dta
.   //merge 1:1 date_ym using `region'_allm
.   //drop _merge
.   //order date_stata date_ym date
. do "$home/data_RiskAdjustments.do"

. ****************************************************
. *Risk factor for different methods
. ****************************************************
. 
. /*
> *If run as standalone, wouold have to create a dataseries of the desired size
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> */
. 
. *****************************
. * Set key parameters
. *pick method
. scalar method   =       6       // pick method 2.3 from R files

. scalar gamma    =       3       // risk aversion coefficient

. 
. *unconditions probability of output disaster
. scalar pyd              = 0.013         // probability of output disaster fro
> m Barro, R file too

. scalar pyd = (1- (1-pyd)^5) // 5-year terms

. 
. * 2) Run the newly created pareto_matrix.do
. do pareto_matrix.do

. matrix Pareto = (0.213,0.207,0.132,0.206,0.213,0.134 ///
>  \ 0.167,0.18,0.213,0.169,0.186,0.2 ///
>  \ 1.04,1.03,1.04,1.03,1.03,1.03 ///
>  \ 5.73,5.7,6.77,6.11,6.67,6.38)

. matrix rownames Pareto = Prob_pid_unc Prob_yd_cond_pid z0 alpha

. matrix list Pareto

Pareto[4,6]
                c1    c2    c3    c4    c5    c6
Prob_pid_unc  .213  .207  .132  .206  .213  .134
Prob_yd_co~d  .167   .18  .213  .169  .186    .2
          z0  1.04  1.03  1.04  1.03  1.03  1.03
       alpha  5.73   5.7  6.77  6.11  6.67  6.38

. 
. 
end of do-file

. 
. 
. *****************************
. *Risk factors for pooled sample
. *  Read off fror R printout for 6 columns of methods: punc, pcond, z0, alpha
. *       matrix Pareto = (0.213,0.207,0.132,0.206,0.213,0.134 ///
> *                               \ 0.167,0.18,0.213,0.169,0.186,0.200 ///
> *                               \ 1.04,1.03,1.04,1.03,1.03,1.03 ///
> *                               \ 5.73,5.7,6.77,6.11,6.67,6.38)
. * rownames Pareto = Prob_pid_unc Prob_yd_cond_pid z0 alpha
. *matrix list Pareto
. 
. *  Calculate adjustments using formula
. scalar z0 = Pareto[3,method] 

. scalar alpha = Pareto[4,method]

. g md = (alpha/(alpha-gamma))*z0^gamma  //formula for m_d

. g ptilde = Pareto[2,method]                // prob (y_d / pi_d)

. g RiskFactor = 1/(1 + ptilde*(md-1))   //formula from paper

. label variable RiskFactor "Risk factor, pooled constant"

. summ RiskFactor ptilde md                  // reads to be 0.82

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
  RiskFactor |        167    .8247283           0   .8247283   .8247283
      ptilde |        167          .2           0         .2         .2
          md |        167    2.062603           0   2.062603   2.062603

. 
. *  Calculate time varying one using second formula -- this actually did not e
> nd up getting used
. * g pinvtilde =  (Pareto[1,method] / pyd )*ptilde // this is prob(pi_d/y_d)
. 
. *clean repeated scalars
. scalar drop z0 alpha 

. 
. *****************************
. *Risk factors for high inflation sample
. *  Read off fror R printout for 6 columns of methods: punc, pcond, z0, alpha
. matrix Paretopos = (0.133,0.129,0.063,0.124,0.131,0.057 ///
>                                 \ 0.203,0.23,0.303,0.227,0.251,0.356 ///
>                                 \ 1.07, 1.03, 1.05, 1.03, 1.03, 1.03 ///
>                                 \ 5.4, 5.11, 5.73, 5.4, 6.09, 5.45)

. matrix rownames Paretopos = Prob_pid_unc Prob_yd_cond_pid z0 alpha

. matrix list Paretopos

Paretopos[4,6]
                c1    c2    c3    c4    c5    c6
Prob_pid_unc  .133  .129  .063  .124  .131  .057
Prob_yd_co~d  .203   .23  .303  .227  .251  .356
          z0  1.07  1.03  1.05  1.03  1.03  1.03
       alpha   5.4  5.11  5.73   5.4  6.09  5.45

. 
. *calculate adjustments using formula
. scalar z0 = Paretopos[3,method] 

. scalar alpha = Paretopos[4,method]

. g md_pos = (alpha/(alpha-gamma))*z0^gamma

. g ptilde_pos = Paretopos[2,method]

. g RiskFactor_pos = 1/(1 + ptilde_pos*(md_pos-1))

. summ RiskFactor_pos ptilde_pos md_pos  // reads to be 0.65

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
RiskFactor~s |        167    .6625366           0   .6625366   .6625366
  ptilde_pos |        167        .356           0       .356       .356
      md_pos |        167     2.43076           0    2.43076    2.43076

. label variable RiskFactor_pos "Risk factor, high-inflation constant"

. 
. *  Calculate time varying one using second formula
. * g pinvtilde_pos =  (Paretopos[1,method] / pyd )*ptilde_pos // this is prob(
> pi_d/y_d)
. 
. *clean repeated scalars
. scalar drop z0 alpha 

. 
. *****************************
. *Risk factors for deflation sample
. *  Read off fror R printout for 6 columns of methods: punc, pcond, z0, alpha
. matrix Paretoneg = (0.105,0.102,0.078,0.105,0.108,0.086 ///
>                                 \ 0.121,0.114,0.142,0.085,0.085,0.085 ///
>                                 \ 1.04, 1.03, 1.04, 1.06, 1.06, 1.06 ///
>                                 \ 10.84, 8.62, 11.55, 15.18, 15.18, 15.18)

. matrix rownames Paretoneg = Prob_pid_unc Prob_yd_cond_pid z0 alpha

. matrix list Paretoneg

Paretoneg[4,6]
                 c1     c2     c3     c4     c5     c6
Prob_pid_unc   .105   .102   .078   .105   .108   .086
Prob_yd_co~d   .121   .114   .142   .085   .085   .085
          z0   1.04   1.03   1.04   1.06   1.06   1.06
       alpha  10.84   8.62  11.55  15.18  15.18  15.18

. 
. *calculate adjustments using formula
. scalar alpha = Paretoneg[4,method]

. scalar z0 = Paretoneg[3,method] 

. g md_neg = (alpha/(alpha-gamma))*z0^gamma

. g ptilde_neg = Paretoneg[2,method]

. g RiskFactor_neg = 1/(1 + ptilde_neg*(md_neg-1))

. summ RiskFactor_neg ptilde_neg md_neg  // reads to be 0.96

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
RiskFactor~g |        167    .9604566           0   .9604566   .9604566
  ptilde_neg |        167        .085           0       .085       .085
      md_neg |        167     1.48437           0    1.48437    1.48437

. label variable RiskFactor_neg "Risk factor, deflation constant"

. 
. *  Calculate time varying one using second formula
. * g pinvtilde_neg =  (Paretoneg[1,method] / pyd )*ptilde_neg // this is prob(
> pi_d/y_d)
. 
. *clean repeated scalars
. scalar drop z0 alpha 

. 
. /*. 
> *Run this bit only if using as standalone
> sleep 100
> save RiskAdjustments, replace

end of do-file

. 
. *do ./data_RiskAdjustments.do
. sleep 500

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_allm.dta saved

. 
. clear

. u "$input/`region'_allm"

. 
. *10 year numbers, tails, with risk factor
. g p4_10y_pool_c = tail4_10y * RiskFactor

. g p4_10y_high_c = tail4_10y * RiskFactor_pos

. g p5_10y_pool_c = tail5_10y * RiskFactor

. g p5_10y_high_c = tail5_10y * RiskFactor_pos

. g p0_10y_low_c = tail0_10y * RiskFactor_neg

. g p0_10y_pool_c = tail0_10y * RiskFactor

. g pm1_10y_pool_c = tailm1_10y * RiskFactor

. g pm1_10y_low_c = tailm1_10y * RiskFactor_neg

. 
. *5 year numbers, tails, with risk factor
. g p4_5y_pool_c = tail4_5y * RiskFactor

. g p4_5y_high_c = tail4_5y * RiskFactor_pos

. g p5_5y_pool_c = tail5_5y * RiskFactor

. g p5_5y_high_c = tail5_5y * RiskFactor_pos

. g p0_5y_low_c = tail0_5y * RiskFactor_neg

. g p0_5y_pool_c = tail0_5y * RiskFactor

. g pm1_5y_pool_c = tailm1_5y * RiskFactor

. g pm1_5y_low_c = tailm1_5y * RiskFactor_neg

. 
. *5y5y numbers, tails, with risk factor
. g p4_5y5y_pool_c = tail4_5y5y * RiskFactor
(1 missing value generated)

. g p4_5y5y_high_c = tail4_5y5y * RiskFactor_pos
(1 missing value generated)

. g p5_5y5y_pool_c = tail5_5y5y * RiskFactor
(1 missing value generated)

. g p5_5y5y_high_c = tail5_5y5y * RiskFactor_pos
(1 missing value generated)

. g p0_5y5y_low_c = tail0_5y5y * RiskFactor_neg
(1 missing value generated)

. g p0_5y5y_pool_c = tail0_5y5y * RiskFactor
(1 missing value generated)

. g pm1_5y5y_pool_c = tailm1_5y5y * RiskFactor
(1 missing value generated)

. g pm1_5y5y_low_c = tailm1_5y5y * RiskFactor_neg
(1 missing value generated)

. 
. sleep 500

. save "$input/`region'_allm", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_allm.dta saved

. 
end of do-file

. do "$home/DATASEs.do"  

. * Merging Seyed's SE estimates into one file for polotting
. 
. *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
. *set more off, perm
. *clear
. *graph drop _all
. *cd "C:/Users/tokay/Nouveau Dossier/Dropbox/HRR_InflDisaster/Ricardo"  // 
. 
. /////////////////////////////////////////////////////////////////////////////
> ///
> import excel "$input/Joint_SE_US.xlsx", sheet("Sheet1")  clear
(4 vars, 44 obs)

. rename A date_ym

. rename B joint_US_lo

. rename C joint_US_hi

. rename D joint_US_probb

. format date_ym %tm

. save "$input/step1", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /step1.dta saved

. clear

. import excel "$input/Joint_SE_EZ.xlsx", sheet("Sheet1")  clear
(4 vars, 44 obs)

. rename A date_ym

. rename B joint_EZ_lo

. rename C joint_EZ_hi

. rename D joint_EZ_probb

. format date_ym %tm

. save "$input/step2", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /step2.dta saved

. clear

. import excel "$input/Pareto_SE_EZ.xlsx", sheet("Sheet1")  clear
(4 vars, 150 obs)

. rename A date_ym

. rename B Pareto_EZ_lo

. rename C Pareto_EZ_hi

. rename D Pareto_EZ_probb

. format date_ym %tm

. save "$input/step3", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /step3.dta saved

. clear

. import excel "$input/Pareto_SE_US.xlsx", sheet("Sheet1")  clear
(4 vars, 152 obs)

. rename A date_ym

. rename B Pareto_US_lo

. rename C Pareto_US_hi

. rename D Pareto_US_probb

. format date_ym %tm

. merge 1:1 date_ym using "$input/step3"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             2
        from master                         2  (_merge==1)
        from using                          0  (_merge==2)

    Matched                               150  (_merge==3)
    -----------------------------------------

. drop _merge

. merge 1:1 date_ym using "$input/step1"

    Result                      Number of obs
    -----------------------------------------
    Not matched                           108
        from master                       108  (_merge==1)
        from using                          0  (_merge==2)

    Matched                                44  (_merge==3)
    -----------------------------------------

. drop _merge

. merge 1:1 date_ym using "$input/step2"

    Result                      Number of obs
    -----------------------------------------
    Not matched                           108
        from master                       108  (_merge==1)
        from using                          0  (_merge==2)

    Matched                                44  (_merge==3)
    -----------------------------------------

. drop _merge

. 
. save "$input/dataSEs", replace 
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /dataSEs.dta saved

. 
end of do-file

. clear

. graph drop _all

. 
. 
. 
. 
. do "$home/figure_estimates-v3.do" //                                    // on
> ly figures that are actially used in new version

. * Estimates for analysis section of paper
. * New file for version 3, August 2024
. 
. *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
. *set more off, perm
. *clear
. *graph drop _all
. *cd  "C:/Users/tokay/Nouveau Dossier/Dropbox/HRR_InflDisaster/Ricardo" // 
. *local dir "C:\Users\PILIPENT\Dropbox\HRR_InflDisaster\Ricardo"  // 
. 
. 
. local updateIteration "2024_11Nov"

. 
. ///////////////////////////////// Graph style ///////////////////////////////
> ///
>     //  ssc install grstyle
.     set scheme s2color

.     grstyle init

. 
.     grstyle color background white

.     // gridlines
.     grstyle color major_grid dimgray

.     grstyle linewidth major_grid thin

.     grstyle yesno draw_major_hgrid yes

.     grstyle yesno grid_draw_min yes

.     grstyle yesno grid_draw_max yes

.     grstyle anglestyle vertical_tick horizontal grstyle color ci_area gs12%50

.     // legend
.     grstyle clockdir legend_position 6

.     grstyle numstyle legend_cols 2

.     grstyle linestyle legend none

. /////////////////////////////////////////////////////////////////////////////
> ///
> 
. 
. ******************************
. * US and EZ 5y5y for introduction -- note need internet access for Fred
. ******************************
. clear

. * EZ data
.         import excel "$home_parent/DataFromBloomberg/Bloomberg_FWISEU55_`upda
> teIteration'.xlsx", sheet("Sheet1") cellrange(A6) firstrow clear
(2 vars, 3,876 obs)

.         rename PX_LAST swap5y5y

.         rename Dates date

.         g m = month(date)

.         g y = year(date)

.         collapse (mean) swap5y5y, by(y m)

.         g date = ym(y,m)

.         format date %tm

.         drop y m 

.         save "$input/EZ_5y5y", replace 
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /EZ_5y5y.dta saved

. * US data 
.         set fredkey 4b647bee15904cd531180baf48767ea4

.         import fred T5YIFR, daterange(2010-01-01 .) aggregate(monthly,avg) cl
> ear

Summary
-------------------------------------------------------------------------------
Series ID                    Nobs    Date range                Frequency
-------------------------------------------------------------------------------
T5YIFR                       184     2010-01-01 to 2025-04-01  Monthly
-------------------------------------------------------------------------------
# of series imported: 1
   highest frequency: Monthly
    lowest frequency: Monthly

.         rename daten date

.         g m = month(date)

.         g y = year(date)

.         replace date = ym(y,m)
(185 real changes made)

.         format date %tm

.         drop y m dates

.         save "$input/US_5y5y", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/input
    > /US_5y5y.dta saved

. * Merge the two
.         merge 1:1 date using "$input/EZ_5y5y"
(variable date was int, now float to accommodate using data's values)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             6
        from master                         6  (_merge==1)
        from using                          0  (_merge==2)

    Matched                               179  (_merge==3)
    -----------------------------------------

.         drop _merge

.         rename T5YIFR US5y5y

.         rename swap5y5y EZ5y5y

. * Figure
.         tsset date

Time variable: date, 2010m1 to 2025m5
        Delta: 1 month

.         keep if date>=ym(2011,1)
(12 observations deleted)

.         tsline US5y5y EZ5y5y, ///
>         lp(solid solid) lw(thick thick) ytitle("%") xtitle("Month") ylabel(0(
> 1)5) tlabel(2011m1(24)2024m12, angle(45)) ///
>         legend(label(1 "United States") label(2 "Eurozone") position(2) ring(
> 0)) ///
>         name(Fives)

.         graph export "$figures/figv3_5y5y.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_5y5y.pdf saved as PDF format

. 
.         
. ******************************
. * Estimates of model parameters
. ******************************
. *US
. clear

. import excel "$input/parameters_mdl101month.xlsx", sheet("US_mdl101_month") f
> irstrow clear
(8 vars, 166 obs)

. generate date_ym = tm(2011m1) + _n -1

. format %tm date_ym

. tsset date_ym

Time variable: date_ym, 2011m1 to 2024m10
        Delta: 1 month

. *keep if date_ym>=ym(2011,1)
. 
.         graph twoway tsline pi_nL pi_nH pi_nn, ///
>         lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") x
> title("Month") ylabel(0(0.05)0.4) tlabel(2011m1(24)2024m12) ///
>         legend(label(1 "p{subscript:dl}") label(2 "p{subscript:dh}") label(3 
> "p{subscript:nn}") position(2) ring(0) row(1)) ///
>         name(modelUS)

.         graph export "$figures/figv3_model101USmonth.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_model101USmonth.pdf saved as PDF format

. 
. *EZ
. clear

. import excel "$input/parameters_mdl101month.xlsx", sheet("EZ_mdl101_month") f
> irstrow clear
(8 vars, 166 obs)

. generate date_ym = tm(2011m1) + _n -1

. format %tm date_ym

. tsset date_ym

Time variable: date_ym, 2011m1 to 2024m10
        Delta: 1 month

. *keep if date_ym>=ym(2011,1)
. 
.         graph twoway tsline pi_nL pi_nH pi_nn, ///
>         lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") x
> title("Month") ylabel(0(0.05)0.4) tlabel(2011m1(24)2024m12) ///
>         legend(label(1 "p{subscript:dl}") label(2 "p{subscript:dh}") label(3 
> "p{subscript:nn}") position(2) ring(0) row(1)) ///
>         name(modelEZ)

.         graph export "$figures/figv3_model101EZmonth.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_model101EZmonth.pdf saved as PDF format

. 
. 
. ******************************
. * US - deflation 2011-14
. ******************************
. clear

. u "$input/US_allm"

. tsset date_ym

Time variable: date_ym, 2009m10 to 2024m10
        Delta: 1 month

. keep if date_ym>=ym(2011,1)
(15 observations deleted)

. keep if date_ym<ym(2015,1)
(118 observations deleted)

. 
.   graph twoway tsline p0_5y5y_low_c pm1_5y5y_low_c, ///
>   lp(solid dash) lw(thick thick ) ytitle("Probability") xtitle("Month") ylabe
> l(0(0.05)0.25) tlabel(2010m12(6)2014m12) ///
>   legend(label(1 "Deflation (<0%)") label(2 "Serious deflation (<-1%)")  posi
> tion(2) ring(0) row(1)) ///
>   name(UStail02)

.   graph export "$figures/figv3_US_def.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_US_def.pdf saved as PDF format

.     
.   graph twoway tsline p0_5y5y_pool_c pm1_5y5y_pool_c, ///
>   lp(solid dash) lw(thick thick ) ytitle("Probability") xtitle("Month") ylabe
> l(0(0.05)0.25) tlabel(2010m12(6)2014m12) ///
>   legend(label(1 "Deflation (<0%)") label(2 "Serious deflation (<-1%)")  posi
> tion(2) ring(0) row(1)) ///
>   name(UStail03)

.   graph export "$figures/figv3_US_def_appxpool.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_US_def_appxpool.pdf saved as PDF format

. ******************************
. * EZ - deflation 2010-19
. ******************************
. clear

. u "$input/EZ_allm"

. tsset date_ym

Time variable: date_ym, 2010m1 to 2024m10, but with a gap
        Delta: 1 month

. keep if date_ym>=ym(2011,1)
(1 observation deleted)

. 
.   graph twoway tsline p0_5y5y_low_c pm1_5y5y_low_c p0_5y_low_c, ///
>   lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") xtitle(
> "Month") ylabel(0(0.05)0.25) tlabel(2011m1(24)2024m12) ///
>   legend(label(1 "Deflation") label(2 "Serious deflation") label(3 "5-year de
> flation")  position(2) ring(0) row(1)) ///
>   name(EZtail01)

.   graph export "$figures/figv3_EZ_def.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_EZ_def.pdf saved as PDF format

. 
. 
.   graph twoway tsline p0_5y5y_pool_c pm1_5y5y_pool_c p0_5y_pool_c, ///
>   lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") xtitle(
> "Month") ylabel(0(0.05)0.25) tlabel(2011m1(24)2024m12) ///
>   legend(label(1 "Deflation") label(2 "Serious deflation") label(3 "5-year de
> flation")  position(2) ring(0) row(1)) ///
>   name(EZtail02)

.   graph export "$figures/figv3_EZ_def_appxpool.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_EZ_def_appxpool.pdf saved as PDF format

. 
. 
. ******************************
. * Pandemic
. ******************************
. clear

. u "$input/US_allm"

. rename p4_5y5y_high_c USp4_5y5y_high_c

. rename p4_10y_high_c USp4_10y_high_c 

. rename p4_5y_high_c USp4_5y_high_c

. *keep date_ym USp4_5y5y_high_c
. merge 1:1 date_ym using "$input/EZ_allm"

    Result                      Number of obs
    -----------------------------------------
    Not matched                            14
        from master                        14  (_merge==1)
        from using                          0  (_merge==2)

    Matched                               167  (_merge==3)
    -----------------------------------------

. rename p4_5y5y_high_c EZp4_5y5y_high_c

. rename p4_5y_high_c EZp4_5y_high_c

. rename p4_10y_high_c EZp4_10y_high_c

. *keep date_ym USp4_5y5y_high_c EZp4_5y5y_high_c
. 
. tsset date_ym

Time variable: date_ym, 2009m10 to 2024m10
        Delta: 1 month

. keep if date_ym>=ym(2020,1)
(123 observations deleted)

. 
.         *Baseline
.         graph twoway tsline USp4_5y5y_high_c EZp4_5y5y_high_c, ///
>         lp(solid dash) lw(thick thick ) ytitle("Probability") xtitle("Month")
>  ylabel(0(0.03)0.15) tlabel(2020m1(12)2024m6) ///
>         legend(label(1 "United States") label(2 "Eurozone")  position(10) rin
> g(0) row(1)) ///
>         name(pandemic, replace)

.         graph export "$figures/figv3_pandemic.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_pandemic.pdf saved as PDF format

. 
.         *5 years
.         graph twoway tsline USp4_5y_high_c EZp4_5y_high_c, ///
>         lp(solid dash) lw(thick thick) ytitle("Probability") xtitle("Month") 
> ylabel(0(0.06)0.36) tlabel(2020m1(12)2024m6) ///
>         legend(label(1 "United States") label(2 "Eurozone")  position(10) rin
> g(0) row(1)) ///
>         name(pandemic5, replace)

.         graph export "$figures/figv3_pandemic5y.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_pandemic5y.pdf saved as PDF format

. 
. 
.         // Joint EZ and US, should be in figure_wesbite, but pain there becau
> se of renaming of variables
.         
. ******************************
. * Pandemic densities
. ******************************
. 
. * US-pandemic case
. clear

. u "$input/US_dist_Z_monthly"

. 
. g temp1=100*frequency if date_stata==mdy(3,4,2020) & dist_identifier=="ZQ10"
(22,785 missing values generated)

. g temp2=100*frequency if date_stata==mdy(3,3,2021) & dist_identifier=="ZQ10"
(22,785 missing values generated)

. g temp3=100*frequency if date_stata==mdy(3,8,2022) & dist_identifier=="ZQ10"
(22,785 missing values generated)

. g temp4=100*frequency if date_stata==mdy(3,2,2023) & dist_identifier=="ZQ10"
(22,785 missing values generated)

. g temp5=100*frequency if date_stata==mdy(3,27,2024) & dist_identifier=="ZQ10"
(22,785 missing values generated)

. 
. label variable temp1    "Mar 2020"

. label variable temp2    "Mar 2021"

. label variable temp3    "Mar 2022"

. label variable temp4    "Mar 2023"

. label variable temp5    "Mar 2024"

. 
. graph twoway mspline temp1 support if support>-0.01 & support<0.06,  lp(solid
>  solid) lw(thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.0
> 6) ylabel(0(5)50) legend(label(1 "Mar 2020") position(1) ring(0)) ///
> || mspline temp2 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(2 "Mar 2021") position(1) ring(0)) ///
> || mspline temp3 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(3 "Mar 2022") position(1) ring(0)) ///
> || mspline temp4 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(4 "Mar 2023") position(1) ring(0)) ///
> || mspline temp5 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(5 "Mar 2024") position(1) ring(0)) ///
> name(USsmoothpandhist)

. graph export "$figures/figv3_US_densities.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_US_densities.pdf saved as PDF format

. 
. * EZ-pandemic case
. clear

. u "$input/EZ_dist_Z_monthly"

. 
. g temp1=100*frequency if date_stata==mdy(3,4,2020) & dist_identifier=="ZQ10"
(21,021 missing values generated)

. g temp2=100*frequency if date_stata==mdy(3,5,2021) & dist_identifier=="ZQ10"
(21,021 missing values generated)

. g temp3=100*frequency if date_stata==mdy(3,8,2022) & dist_identifier=="ZQ10"
(21,021 missing values generated)

. g temp4=100*frequency if date_stata==mdy(3,2,2023) & dist_identifier=="ZQ10"
(21,021 missing values generated)

. g temp5=100*frequency if date_stata==mdy(3,19,2024) & dist_identifier=="ZQ10"
(21,021 missing values generated)

. 
. label variable temp1    "Mar 2020"

. label variable temp2    "Mar 2021"

. label variable temp3    "Mar 2022"

. label variable temp4    "Mar 2023"

. label variable temp5    "Mar 2024"

. 
. graph twoway mspline temp1 support if support>-0.01 & support<0.06,  lp(solid
>  solid) lw(thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.0
> 6) ylabel(0(5)50) legend(label(1 "Mar 2020") position(1) ring(0)) ///
> || mspline temp2 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(2 "Mar 2021") position(1) ring(0)) ///
> || mspline temp3 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(3 "Mar 2022") position(1) ring(0)) ///
> || mspline temp4 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(4 "Mar 2023") position(1) ring(0)) ///
> || mspline temp5 support  if support>-0.01 & support<0.06, lp(solid solid) lw
> (thick thick) ytitle("%") xtitle("Inflation") xlabel(-0.01(0.01)0.06) ylabel(
> 0(5)50) legend(label(5 "Mar 2024") position(1) ring(0)) ///
> name(EZsmoothpandhist)

. graph export "$figures/figv3_EZ_densities.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_EZ_densities.pdf saved as PDF format

. 
. 
.         
. ******************************
. * Effect of initial conditions on disaster probabilities for EZ and US
. ******************************
. 
. ******* US
. clear

. import excel "$input/Initial_US.xlsx", sheet("Bins") firstrow  clear
(11 vars, 166 obs)

. gen date=ym(year,month)

. format date %tm

. * Risk factor correction
.         replace Baseline=Baseline*0.662
(166 real changes made)

.         forvalues i=1/8{        
  2.                 replace Bin`i'=Bin`i'*0.662
  3.         }
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)

. 
. drop if date <ym(2022,1)
(132 observations deleted)

.         graph twoway connected Baseline Bin5 Bin7 date, ///
>         lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") x
> title("Month") ylabel(0(0.03)0.15) tlabel(2022m1(6)2025m1) ///
>         legend(label( 1 "Baseline") label(2 "(2,3]") label(3 "(4,5]") positio
> n(1) ring(0) row(1)) ///
>         name(USinitial, replace)

.         graph export "$figures/figv3_US_initial.pdf",replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_US_initial.pdf saved as PDF format

. 
. ******* EZ
. clear

. import excel "$input/Initial_EZ.xlsx", sheet("Bins") firstrow  clear
(11 vars, 166 obs)

. gen date=ym(year,month)

. format date %tm

. * Risk factor correction
.         replace Baseline=Baseline*0.662
(166 real changes made)

.         forvalues i=1/8{        
  2.                 replace Bin`i'=Bin`i'*0.662
  3.         }
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)
(166 real changes made)

. 
. drop if date <ym(2022,1)
(132 observations deleted)

.         graph twoway connected Baseline Bin5 Bin7 date, ///
>         lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") x
> title("Month") ylabel(0(0.03)0.15) tlabel(2022m1(6)2025m1) ///
>         legend(label( 1 "Baseline") label(2 "(2,3]") label(3 "(4,5]") positio
> n(1) ring(0) row(1)) ///
>         name(EZinitial, replace)

.         graph export "$figures/figv3_EZ_initial.pdf",replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_EZ_initial.pdf saved as PDF format

. 
. 
. ******************************
. * Conditional probabilities
. ******************************
. 
. ******* US
. clear

. import excel "$input/Conditional_US_new.xlsx", sheet("Sheet1") firstrow clear
(5 vars, 46 obs)

. format Date %tm

. * Corrected Risk Factor 
.         replace Year0=Year0*0.662
(46 real changes made)

.         replace Year1=Year1*0.662
(46 real changes made)

.         replace Year2=Year2*0.662
(45 real changes made)

. 
. drop if Date <ym(2022,1)
(12 observations deleted)

.         graph twoway connected Year0 Year1 Year2 Date, ///
>         lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") x
> title("Month") ylabel(0(0.03)0.15) tlabel(2022m1(6)2025m1) ///
>         legend(label( 1 "Baseline") label(2 "1-year") label(3 "2-year") posit
> ion(1) ring(0) row(1)) ///
>         name(USconditional, replace)

.         graph export "$figures/figv3_US_conditional.pdf",replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_US_conditional.pdf saved as PDF format

. 
. ******* EZ
. clear

. import excel "$input/Conditional_EZ_new.xlsx", sheet("Sheet1") firstrow clear
(4 vars, 46 obs)

. format Date %tm

. * Corrected Risk Factor 
.         replace Year0=Year0*0.662
(46 real changes made)

.         replace Year1=Year1*0.662
(46 real changes made)

.         replace Year2=Year2*0.662
(46 real changes made)

. 
. drop if Date <ym(2022,1)
(12 observations deleted)

.         graph twoway connected Year0 Year1 Year2 Date, ///
>         lp(solid dash dash_dot) lw(thick thick thick) ytitle("Probability") x
> title("Month") ylabel(0(0.03)0.15) tlabel(2022m1(6)2025m1) ///
>         legend(label( 1 "Baseline") label(2 "1-year") label(3 "2-year") posit
> ion(1) ring(0) row(1)) ///
>         name(EZconditional, replace)

.         graph export "$figures/figv3_EZ_conditional.pdf",replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_EZ_conditional.pdf saved as PDF format

. 
. ******************************
. * Standard errors
. ******************************
. clear

. u "$input/dataSEs"

. format date_ym %tm

. tsset date_ym

Time variable: date_ym, 2010m1 to 2023m8, but with a gap
        Delta: 1 month

. keep if date_ym>=ym(2011,1)
(1 observation deleted)

. 
. *** Plot
.         graph twoway (rarea Pareto_US_lo Pareto_US_hi date_ym, color(%60)), y
> title("Probability") xtitle("Month") ylabel(0(0.03)0.15) name(SEpareto)

.         graph export "$figures/figv3_SEpareto.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_SEpareto.pdf saved as PDF format

. 
. keep if date_ym>=ym(2020,1)
(107 observations deleted)

.         graph twoway (rarea joint_US_lo joint_US_hi date_ym, color(%60)), yti
> tle("Probability") xtitle("Month") ylabel(0(0.03)0.15)     name(SEjoint)

.         graph export "$figures/figv3_SEjoint.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/figv3_SEjoint.pdf saved as PDF format

. 
end of do-file

. foreach region of local regions {
  2.     clear all
  3.     do "$home/figure_dynamics.do" `region' // Model parameter estimates
  4.     do "$home/figure_riskpremia.do" `region' // Risk premia
  5. }

. * Ploting Inflation dynamics model parameter estimates
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "US"     // set region US or EZ, so must run program twice
> */
. 
. local region `1'

. 
. ///////////////////////////////// Graph style ///////////////////////////////
> ///
>     //  ssc install grstyle
.     set scheme s2color

.     grstyle init

. 
.     grstyle color background white

.     // gridlines
.     grstyle color major_grid dimgray

.     grstyle linewidth major_grid thin

.     grstyle yesno draw_major_hgrid yes

.     grstyle yesno grid_draw_min yes

.     grstyle yesno grid_draw_max yes

.     grstyle anglestyle vertical_tick horizontal grstyle color ci_area gs12%50

.     // legend
.     grstyle clockdir legend_position 6

.     grstyle numstyle legend_cols 2

.     grstyle linestyle legend none

. /////////////////////////////////////////////////////////////////////////////
> ///
> 
. 
. /////////////////////////////////////////
> clear

. import excel "$input/parameters_mdl101month.xlsx", sheet("`region'_mdl101_mon
> th") firstrow clear
(8 vars, 166 obs)

. generate date_ym = tm(2011m1) + _n -1

. format %tm date_ym

. 
. twoway line pi_nL pi_nH pi_nn date_ym, ///
> lw(thick thick thick) xtitle("month") legend(label(1 "p{subscript:dl}") label
> (2 "p{subscript:dh}") label(3 "p{subscript:nn}") size(*1.5) position(2) ring(
> 0) row(1)) ylabel(0(0.05)0.5) tlabel(2011m1(24)2024m5, angle(45))

. 
. graph export "$figures/fig_model101`region'month.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/fig_model101USmonth.pdf saved as PDF format

. 
end of do-file

. * Risk premia
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "EZ"     // set region US or EZ, so must run program twice
> */
. 
. local region `1'         // set region US or EZ, so must run program twice

. 
. ///////////////////////////////// Graph style ///////////////////////////////
> ///
>     //  ssc install grstyle
.     set scheme s2color

.     grstyle init

. 
.     grstyle color background white

.     // gridlines
.     grstyle color major_grid dimgray

.     grstyle linewidth major_grid thin

.     grstyle yesno draw_major_hgrid yes

.     grstyle yesno grid_draw_min yes

.     grstyle yesno grid_draw_max yes

.     grstyle anglestyle vertical_tick horizontal grstyle color ci_area gs12%50

.     // legend
.     grstyle clockdir legend_position 6

.     grstyle numstyle legend_cols 2

.     grstyle linestyle legend none

. /////////////////////////////////////////////////////////////////////////////
> ///
> 
. clear

. u "$input/`region'_allm"

. 
. *Risk premia
. g rph_10y_pool_c = (p4_10y_pool_c - tail4_10y) / (tail5_10y-tail4_10y)
(1 missing value generated)

. g rpl_10y_pool_c = - (p0_10y_pool_c - tail0_10y) / (tailm1_10y-tail0_10y)
(1 missing value generated)

. g rph_10y_high_c = (p4_10y_high_c - tail4_10y) / (tail5_10y-tail4_10y)
(1 missing value generated)

. g rpl_10y_low_c = - (p0_10y_low_c - tail0_10y) / (tailm1_10y-tail0_10y)
(1 missing value generated)

. 
. tsset date_ym

Time variable: date_ym, 2009m10 to 2024m10
        Delta: 1 month

. graph twoway tsline rph_10y_pool_c rph_10y_high_c rpl_10y_low_c, ///
> lp(dash solid solid) lw(thick thick thick) ytitle("%") xtitle("Month") ylabel
> (-0.30(0.10)0.70) tlabel(2010m1(24)2024m5) ///
> legend(label(1 "Pooled estimate") label(2 "High inflation") label(3 "Low infl
> ation") position(6) ring(0)) ///
> name(RiskPremia)

. graph export "$figures/fig_`region'_riskpremia.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/fig_US_riskpremia.pdf saved as PDF format

. 
end of do-file

. * Ploting Inflation dynamics model parameter estimates
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "US"     // set region US or EZ, so must run program twice
> */
. 
. local region `1'

. 
. ///////////////////////////////// Graph style ///////////////////////////////
> ///
>     //  ssc install grstyle
.     set scheme s2color

.     grstyle init

. 
.     grstyle color background white

.     // gridlines
.     grstyle color major_grid dimgray

.     grstyle linewidth major_grid thin

.     grstyle yesno draw_major_hgrid yes

.     grstyle yesno grid_draw_min yes

.     grstyle yesno grid_draw_max yes

.     grstyle anglestyle vertical_tick horizontal grstyle color ci_area gs12%50

.     // legend
.     grstyle clockdir legend_position 6

.     grstyle numstyle legend_cols 2

.     grstyle linestyle legend none

. /////////////////////////////////////////////////////////////////////////////
> ///
> 
. 
. /////////////////////////////////////////
> clear

. import excel "$input/parameters_mdl101month.xlsx", sheet("`region'_mdl101_mon
> th") firstrow clear
(8 vars, 166 obs)

. generate date_ym = tm(2011m1) + _n -1

. format %tm date_ym

. 
. twoway line pi_nL pi_nH pi_nn date_ym, ///
> lw(thick thick thick) xtitle("month") legend(label(1 "p{subscript:dl}") label
> (2 "p{subscript:dh}") label(3 "p{subscript:nn}") size(*1.5) position(2) ring(
> 0) row(1)) ylabel(0(0.05)0.5) tlabel(2011m1(24)2024m5, angle(45))

. 
. graph export "$figures/fig_model101`region'month.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/fig_model101EZmonth.pdf saved as PDF format

. 
end of do-file

. * Risk premia
. 
. /*
> *Run this block if stand alone. If commented out, it is because this will be 
> run from _ricardo_master.do
> set more off, perm
> clear
> graph drop _all
> local dir "/Users/rreis/Dropbox/05Shared_folders/HRR/HRR_InflDisaster/Ricardo
> "  // RR's directory
> *local dir "C:\Users\marin\Dropbox\HRR_InflDisaster\Ricardo"  // Marina's dir
> ectory
> cd `dir'
> local region = "EZ"     // set region US or EZ, so must run program twice
> */
. 
. local region `1'         // set region US or EZ, so must run program twice

. 
. ///////////////////////////////// Graph style ///////////////////////////////
> ///
>     //  ssc install grstyle
.     set scheme s2color

.     grstyle init

. 
.     grstyle color background white

.     // gridlines
.     grstyle color major_grid dimgray

.     grstyle linewidth major_grid thin

.     grstyle yesno draw_major_hgrid yes

.     grstyle yesno grid_draw_min yes

.     grstyle yesno grid_draw_max yes

.     grstyle anglestyle vertical_tick horizontal grstyle color ci_area gs12%50

.     // legend
.     grstyle clockdir legend_position 6

.     grstyle numstyle legend_cols 2

.     grstyle linestyle legend none

. /////////////////////////////////////////////////////////////////////////////
> ///
> 
. clear

. u "$input/`region'_allm"

. 
. *Risk premia
. g rph_10y_pool_c = (p4_10y_pool_c - tail4_10y) / (tail5_10y-tail4_10y)

. g rpl_10y_pool_c = - (p0_10y_pool_c - tail0_10y) / (tailm1_10y-tail0_10y)

. g rph_10y_high_c = (p4_10y_high_c - tail4_10y) / (tail5_10y-tail4_10y)

. g rpl_10y_low_c = - (p0_10y_low_c - tail0_10y) / (tailm1_10y-tail0_10y)

. 
. tsset date_ym

Time variable: date_ym, 2010m1 to 2024m10, but with a gap
        Delta: 1 month

. graph twoway tsline rph_10y_pool_c rph_10y_high_c rpl_10y_low_c, ///
> lp(dash solid solid) lw(thick thick thick) ytitle("%") xtitle("Month") ylabel
> (-0.30(0.10)0.70) tlabel(2010m1(24)2024m5) ///
> legend(label(1 "Pooled estimate") label(2 "High inflation") label(3 "Low infl
> ation") position(6) ring(0)) ///
> name(RiskPremia)

. graph export "$figures/fig_`region'_riskpremia.pdf", replace
file C:/Users/tokay/Nouveau
    Dossier/Dropbox/HRR_InflDisaster/Replication/InfDisaster_RepPackage/Figur
    > es/fig_EZ_riskpremia.pdf saved as PDF format

. 
end of do-file

. clear

. graph drop _all

. 
end of do-file
